<?php

namespace app\index\controller;

use think\Controller;
use think\Db;
use think\Session;

class Login extends Controller {

    public function index() {
        if($this->request->isPost()){
            $data = input('post.');
            
            //会员登录
            $info = $this->handlingErrors(httpGet(config('api_addr') . 'applogin',$data), 'applogin');
            
            if(is_string($info)){
                $this->error($info);
            }else{
                $data = array_merge($data, $info);
                
                //我的课程
                $course_list = $this->handlingErrors(httpGet(config('api_addr') . 'querycusbuycourselist',['userId'=>$data['id']]), 'querycusbuycourselist');
                if($course_list){
                    
                    //统计所有课程id
                    foreach ($course_list as $k=>$v){
                        $courses[] = courses($v['courseId']);
                    }
                                 
                    
                    if(array_filter($courses)){
                        foreach ($courses as $kk=>$vv){
                            Session::set($vv,1); //对应题目的名称
                        }
                    }else{
                        $this->error('该题库只开放宏景AICPI学员');
                    }
                    
                }else{
                    $this->error('该题库只开放宏景AICPI学员');
                }
                
                Session::set('user_id',$data['id']); //会员id

                $this->success('登录成功',url('Lists/lists'));
            }
        }
        
        $this->view->engine->layout(false);
        return $this->fetch();
    }
    
    
    
    

}
